object quick_sort {
  def main(args: Array[String]) {
    var my_array = Array(1, 9, 45, 7, 15, -5, 2, 74, -27, 10)
    my_array = quick_sort(my_array, 0, my_array.size - 1)
    for (a <- my_array)
      printf("%d ", a)
    println()
  }

  def quick_sort(array: => Array[Int], low: Int, high: Int): Array[Int] = {
    if (low < high) {
      var left: Int = low
      var right: Int = high
      val pivot: Int = array(low)
      while (left < right) {
        while (left < right && array(right) >= pivot)
          right -= 1
        if (left < right) {
          array(left) = array(right)
          left += 1
        }
        while (left < right && array(left) < pivot)
          left += 1
        if (left < right) {
          array(right) = array(left)
          right -= 1
        }
      }
      array(left) = pivot
      quick_sort(array, low, left - 1)
      quick_sort(array, right + 1, high)
    }
    return array
  }
}
